package com.css.fxfzysx.modules.vabStructure.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzysx.base.attachment.repository.AttachmentInfoRepository;
import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.common.utils.BeanUtil;
import com.css.fxfzysx.common.utils.UpdateUtil;
import com.css.fxfzysx.constants.FxfzConstants;
import com.css.fxfzysx.modules.cztDataMange.constans.RedisKeyConstants;
import com.css.fxfzysx.modules.cztDataMange.entity.CbcbDetailEntity;
import com.css.fxfzysx.modules.cztDataMange.entity.CbcbInfoEntity;
import com.css.fxfzysx.modules.cztDataMange.entity.CbcpInfoEntity;
import com.css.fxfzysx.modules.cztDataMange.repository.BacInformationRepository;
import com.css.fxfzysx.modules.cztDataMange.utils.GenerationNumberUtil;
import com.css.fxfzysx.modules.vabStructure.constans.BuildingRoofEnum;
import com.css.fxfzysx.modules.vabStructure.constans.BuildingSeismicResistanceEnum;
import com.css.fxfzysx.modules.vabStructure.constans.CorrectionCiEnum;
import com.css.fxfzysx.modules.vabStructure.entity.CztBrickConcreteDestroyCalc;
import com.css.fxfzysx.modules.vabStructure.entity.CztBrickConcreteDestroyResult;
import com.css.fxfzysx.modules.vabStructure.param.CbcpInfoParam;
import com.css.fxfzysx.modules.vabStructure.repository.PobStructureRepository;
import com.css.fxfzysx.modules.vabStructure.service.PobStructureService;
import com.css.fxfzysx.modules.vabStructure.vo.PobStructureVO;
import com.css.fxfzysx.modules.ysxManagement.entity.ZqtEntity;
import com.css.fxfzysx.modules.ysxManagement.repository.ZqtCiRepository;
import com.css.fxfzysx.util.*;
import com.css.fxfzysx.web.PlatformSessionContext;
import com.css.fxfzysx.zcpt.sys.entity.SUser;
import com.css.fxfzysx.zcpt.sys.service.SUserService;
import com.css.fxfzysx.zcpt.sys.service.SysRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

@Service
@Slf4j
public class PobStructureServiceImpl implements PobStructureService {

    @Resource
    private PobStructureRepository pobStructureRepository;

    @Resource
    private BacInformationRepository bacInformationRepository;

    @Resource
    private SysRoleService roleService;

    @Resource
    private ZqtCiRepository zqtCiRepository;

    @Resource
    private AttachmentInfoRepository attachmentInfoRepository;

    @Resource
    private GenerationNumberUtil generationNumberUtil;
    @Resource
    SUserService sUserService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse countPobStructure(Map<String, Object> paramMap) {
        JSONObject jsonObject = new JSONObject();
        /**
         * key:建筑编号
         * values:
         *      jsonObject:
         *          cbcbInfoEntity 建筑信息（楼）
         *          detailList  楼的详情（楼层）
         */
        Map<String, JSONObject> map = new HashMap<>();
        String cbcbiIds = (String) paramMap.get("ids");
        if (PlatformObjectUtils.isNotEmpty(cbcbiIds)) {
            List<String> ids = Arrays.asList(cbcbiIds.split(","));
            pobStructureRepository.delByProjectId1(ids);
            pobStructureRepository.delByProjectId2(ids);
            for (String id : ids) {
                JSONObject jsonObject1 = new JSONObject();
                CbcbInfoEntity cbcbInfoEntity = bacInformationRepository.getCbcbiById(id);
                jsonObject1.put("cbcbInfoEntity", cbcbInfoEntity);
                jsonObject1.put("detailList", bacInformationRepository.getCbcbdById(id));
                map.put(cbcbInfoEntity.getBuildingNumber(), jsonObject1);
            }
        } else {
            CbcbInfoEntity cbcbInfoEntity = JSON.parseObject(JSON.toJSONString(paramMap.get("cbcbInfoEntity")), CbcbInfoEntity.class);
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("cbcbInfoEntity", cbcbInfoEntity);
            List<CbcbDetailEntity> detailList = JSON.parseArray(JSON.toJSONString(paramMap.get("detailList")), CbcbDetailEntity.class);
            jsonObject1.put("detailList", detailList);
            map.put(cbcbInfoEntity.getBuildingNumber(), jsonObject1);
        }

        String ciId = "";
        List<CztBrickConcreteDestroyCalc> cztBrickConcreteDestroyCalcs = new ArrayList<>();
        List<CztBrickConcreteDestroyResult> cztBrickConcreteDestroyResults = new ArrayList<>();
        for (Map.Entry<String, JSONObject> entry : map.entrySet()) {
            JSONObject value = entry.getValue();
            CbcbInfoEntity cbcbInfoEntity = JSON.parseObject(JSON.toJSONString(value.getJSONObject("cbcbInfoEntity")),
                    CbcbInfoEntity.class);
            cbcbInfoEntity.setCalculateOrNot("1");
            Integer n = cbcbInfoEntity.getTotalFloor();//总楼层数
            //根据条件查询具体的值
            //结构无明显质量问题，1有：2不满足；2无：1满足
            String name1 = null;
            if (1 == cbcbInfoEntity.getCiType1Value()) {
                name1 = "不满足";
            } else {
                name1 = "满足";
            }
            ZqtEntity type1 = zqtCiRepository.getZqtByConditionAndValue(cbcbInfoEntity.getCiType1(), name1);
            //平立面规则，规则：满足；不规则：不满足
            String name2 = null;
            if (1 == cbcbInfoEntity.getCiType2Value()) {
                name2 = "满足";
            } else {
                name2 = "不满足";
            }
            ZqtEntity type2 = zqtCiRepository.getZqtByConditionAndValue(cbcbInfoEntity.getCiType2(), name2);
            //建筑抗震设计规范
            ZqtEntity type3 = zqtCiRepository.getZqtByConditionAndValue(BuildingSeismicResistanceEnum.getByCode(cbcbInfoEntity.getCiType3Value()), "满足");
            //楼屋盖类型
            Double type4 = BuildingRoofEnum.getByCode(cbcbInfoEntity.getCiType4Value(), cbcbInfoEntity.getSpacing(), BuildingRoofEnum.getByName(cbcbInfoEntity.getFortification()));
            BigDecimal ci = BigDecimal.valueOf(type1.getCiValue() + type2.getCiValue() + type3.getCiValue() + type4);
            cbcbInfoEntity.setCi(ci);
            ciId = type1.getCbrmId() + "," + type2.getCbrmId() + "," + type3.getCbrmId();
            cbcbInfoEntity.setCorrectionCoefficient(ciId);
            // bacInformationRepository.updateCbcbInfo(cbcbInfoEntity);

            BigDecimal As = BigDecimal.ZERO;
            BigDecimal rs = BigDecimal.ZERO;
            BigDecimal Rs = BigDecimal.ZERO;
            BigDecimal Ds = BigDecimal.ZERO;
            BigDecimal Dsm = BigDecimal.ZERO;
            Map<Integer, JSONObject> jsonMap1 = new HashMap<>();
            Map<Integer, JSONObject> jsonMap2 = new HashMap<>();
            Map<Integer, Map<String, Integer>> mapMap = new HashMap<>();
            List<CbcbDetailEntity> detailList = JSON.parseArray(JSON.toJSONString(value.getJSONArray("detailList")),
                    CbcbDetailEntity.class);
            for (CbcbDetailEntity cbcbDetailEntity : detailList) {
                double Rm = cbcbDetailEntity.getMortar() * 10;//楼层对应的砂浆标号
                BigDecimal Fs = cbcbDetailEntity.getSectionArea().divide(BigDecimal.valueOf(10000), 10, BigDecimal.ROUND_UP);//墙体截面积
                BigDecimal as = cbcbDetailEntity.getBuildArea().divide(BigDecimal.valueOf(10000), 10, BigDecimal.ROUND_UP);//建筑面积
                int i = cbcbDetailEntity.getFloorNumber();//楼层序号
                rs = BigDecimal.valueOf(0.14).multiply(BigDecimal.valueOf(n - i + 1)).add(BigDecimal.valueOf(0.014 * Rm)).add(BigDecimal.valueOf(0.5)).setScale(2,RoundingMode.HALF_UP);
                As = BigDecimal.valueOf(2 * n + 1).divide(BigDecimal.valueOf(3 * ((n + i) * (n - i + 1)) / 2), 2,
                        BigDecimal.ROUND_HALF_UP);
                Rs = As.multiply(Fs.divide(BigDecimal.valueOf(2).multiply(as), 10, BigDecimal.ROUND_HALF_UP)).multiply(rs).setScale(2,RoundingMode.HALF_UP);

                CztBrickConcreteDestroyCalc entity1 = new CztBrickConcreteDestroyCalc();
                entity1.setProjectId(cbcbInfoEntity.getCbcbiId());
                entity1.setCs(i);
                entity1.setQtkjcd(rs);
                entity1.setDzjlzsxs(As);
                entity1.setResistanceForce(Rs);

                for (int j = 6; j < 11; j++) {
                    switch (j) {
                        case 6:
                            Ds = BigDecimal.valueOf(2.032).subtract(BigDecimal.valueOf(0.007).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD6(Ds);
                            break;
                        case 7:
                            Ds = BigDecimal.valueOf(1.977).subtract(BigDecimal.valueOf(0.006).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD7(Ds);
                            break;
                        case 8:
                            Ds = BigDecimal.valueOf(1.975).subtract(BigDecimal.valueOf(0.005).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD8(Ds);
                            break;
                        case 9:
                            Ds = BigDecimal.valueOf(1.866).subtract(BigDecimal.valueOf(0.004).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD9(Ds);
                            break;
                        case 10:
                            Ds = BigDecimal.valueOf(1.74).subtract(BigDecimal.valueOf(0.003).multiply(Rs)).setScale(2, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD10(Ds);
                            break;
                    }
                    // cbcbDetailEntity.setCi(ci);
                    // BigDecimal ci = cbcbInfoEntity.getCi();
                    Dsm = Ds.multiply(BigDecimal.valueOf(1).add(ci)).setScale(2, RoundingMode.HALF_UP);
                    switch (j) {
                        case 6:
                            entity1.setDegree6(Dsm);
                            break;
                        case 7:
                            entity1.setDegree7(Dsm);
                            break;
                        case 8:
                            entity1.setDegree8(Dsm);
                            break;
                        case 9:
                            entity1.setDegree9(Dsm);
                            break;
                        case 10:
                            entity1.setDegree10(Dsm);
                            break;
                    }
                    JSONObject jsonObject1 = null;
                    if (jsonMap1.containsKey(j)) {
                        jsonObject1 = jsonMap1.get(j);
                    } else {
                        jsonObject1 = new JSONObject();
                    }
                    jsonObject1.put("f" + i, Dsm);
                    jsonMap1.put(j, jsonObject1);
                    String DsmL = null;
                    if (Dsm.compareTo(BigDecimal.valueOf(0.1)) <= 0) {
                        DsmL = "基本完好";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.1)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.3)) <= 0) {
                        DsmL = "轻微破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.3)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.55)) <= 0) {
                        DsmL = "中等破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.55)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.85)) <= 0) {
                        DsmL = "严重破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.85)) > 0) {
                        DsmL = "毁坏";
                    }
                    JSONObject jsonObject2 = null;
                    if (jsonMap2.containsKey(j)) {
                        jsonObject2 = jsonMap2.get(j);
                    } else {
                        jsonObject2 = new JSONObject();
                    }
                    jsonObject2.put("floor" + i, DsmL);
                    jsonMap2.put(j, jsonObject2);

                    Map<String, Integer> map1 = null;
                    if (mapMap.containsKey(j)) {
                        map1 = mapMap.get(j);
                    } else {
                        map1 = new HashMap<>();
                    }
                    Integer integer = 0;
                    if (map1.containsKey(DsmL)) {
                        integer = map1.get(DsmL);
                        integer++;
                    } else {
                        integer = 1;
                    }
                    map1.put(DsmL, integer);
                    mapMap.put(j, map1);
                }
                saveBrickConcreteDestroyCalc(entity1);
                cztBrickConcreteDestroyCalcs.add(entity1);
            }
            for (int k = 6; k < 11; k++) {
                CztBrickConcreteDestroyResult entity = new CztBrickConcreteDestroyResult();
                entity.setProjectId(cbcbInfoEntity.getCbcbiId());
                entity.setBreakState(k + "度");
                entity.setJsonData1(jsonMap1.get(k).toJSONString());
                entity.setJsonData2(jsonMap2.get(k).toJSONString());
                /*Integer num = 0;
                String conclusion = "";
                for (Map.Entry<String, Integer> entry1 : mapMap.get(k).entrySet()) {
                    if (num.compareTo(entry1.getValue()) == 0) {
                        conclusion = conclusion + "," + entry1.getKey();
                    } else if (num.compareTo(entry1.getValue()) < 0) {
                        conclusion = entry1.getKey();
                        num = entry1.getValue();
                    }
                }
                if (conclusion.indexOf(",") == 0) {
                    conclusion = conclusion.substring(1);
                }*/
                entity.setConclusion(getConclusion(mapMap,k));
                saveCztBrickConcreteDestroyResult(entity);
                cztBrickConcreteDestroyResults.add(entity);
            }
            if (PlatformObjectUtils.isNotEmpty(cbcbiIds)) {
                pobStructureRepository.updateCalculateOrNotStatusById(cbcbInfoEntity.getCbcbiId());
            }
            jsonObject.put("cbcbInfoEntity", cbcbInfoEntity);
            jsonObject.put("detailList", detailList);
        }
        getData(jsonObject, cztBrickConcreteDestroyCalcs, cztBrickConcreteDestroyResults);
        jsonObject.put("ciId", ciId);
        return RestResponse.succeed(jsonObject);
    }

    /**
     * 获取结论
     *
     * @param map
     * @param k
     * @return
     */
    public static String getConclusion(Map<Integer, Map<String, Integer>> map, Integer k) {
        String conclusion = "";
        Map<String, Integer> destructiveState = map.get(k);
        if(destructiveState.toString().contains("基本完好")){
            conclusion = "基本完好";
        }
        if(destructiveState.toString().contains("轻微破坏")){
            conclusion = "轻微破坏";
        }
        if(destructiveState.toString().contains("中等破坏")){
            conclusion = "中等破坏";
        }
        if(destructiveState.toString().contains("严重破坏")){
            conclusion = "严重破坏";
        }
        if(destructiveState.toString().contains("毁坏")){
            conclusion = "毁坏";
        }
        return conclusion;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse countPobStructure1(CbcpInfoParam cbcpInfoParam) {
        ArrayList<CbcpInfoEntity> cbcpInfoEntities = new ArrayList<>();
        if (PlatformObjectUtils.isNotEmpty(cbcpInfoParam.getIds())) {
            List<String> ids = Arrays.asList(cbcpInfoParam.getIds().split(","));
            pobStructureRepository.delByProjectId1(ids);
            pobStructureRepository.delByProjectId2(ids);
            for (String id : ids) {
                cbcpInfoEntities.add(bacInformationRepository.getCbcById1(id));
            }
        } else {
            cbcpInfoEntities.add(cbcpInfoParam.getCbcpInfoEntity());
        }
        String ciId = "";
        List<CztBrickConcreteDestroyCalc> cztBrickConcreteDestroyCalcs = new ArrayList<>();
        List<CztBrickConcreteDestroyResult> cztBrickConcreteDestroyResults = new ArrayList<>();
        try {
            for (CbcpInfoEntity cbcpInfoEntity : cbcpInfoEntities) {
                Integer n = cbcpInfoEntity.getTotalFloor();//总楼层数
                Integer i = Integer.valueOf(cbcpInfoEntity.getFloor());//楼层数
                double Rm = cbcpInfoEntity.getMortar() * 10;//楼层对应的砂浆标号
                BigDecimal Fs = cbcpInfoEntity.getSectionArea();//墙体截面积
                BigDecimal as = cbcpInfoEntity.getBuildArea();//建筑面积
                BigDecimal As = BigDecimal.ZERO;
                BigDecimal rs = BigDecimal.ZERO;
                BigDecimal Rs = BigDecimal.ZERO;
                BigDecimal Ds = BigDecimal.ZERO;
                BigDecimal Dsm = BigDecimal.ZERO;
                Map<Integer, JSONObject> jsonMap1 = new HashMap<>();
                Map<Integer, JSONObject> jsonMap2 = new HashMap<>();
                Map<Integer, Map<String, Integer>> mapMap = new HashMap<>();

                //根据条件查询具体的值
                ZqtEntity type1 = zqtCiRepository.getZqtByConditionAndValue(cbcpInfoEntity.getCiType1(), CorrectionCiEnum.getByCode(cbcpInfoEntity.getCiType1Value()));
                ZqtEntity type2 = zqtCiRepository.getZqtByConditionAndValue(cbcpInfoEntity.getCiType2(), CorrectionCiEnum.getByCode(cbcpInfoEntity.getCiType2Value()));
                ZqtEntity type3 = zqtCiRepository.getZqtByConditionAndValue(BuildingSeismicResistanceEnum.getByCode(cbcpInfoEntity.getCiType3Value()), "满足");
                Double type4 = BuildingRoofEnum.getByCode(cbcpInfoEntity.getCiType4Value(), cbcpInfoEntity.getSpacing(), BuildingRoofEnum.getByName(cbcpInfoEntity.getFortification()));
                BigDecimal ci = BigDecimal.valueOf(type1.getCiValue() + type2.getCiValue() + type3.getCiValue() + type4);

                ciId = type1.getCbrmId() + "," + type2.getCbrmId() + "," + type3.getCbrmId();

                rs = BigDecimal.valueOf(0.14).multiply(BigDecimal.valueOf(n - i + 1)).add(BigDecimal.valueOf(0.014 * Rm)).add(BigDecimal.valueOf(0.5));
                As = BigDecimal.valueOf(2 * n + 1).divide(BigDecimal.valueOf(3 * ((i + n) * (n - i + 1)) / 2), 2, BigDecimal.ROUND_HALF_UP);
                Rs = As.multiply(Fs.divide(BigDecimal.valueOf(2).multiply(as), 4, BigDecimal.ROUND_HALF_UP)).multiply(rs).setScale(2, RoundingMode.HALF_UP);

                CztBrickConcreteDestroyCalc entity1 = new CztBrickConcreteDestroyCalc();
                entity1.setProjectId(cbcpInfoEntity.getCbcpiId());
                entity1.setCs(i);
                entity1.setQtkjcd(rs);
                entity1.setDzjlzsxs(As);
                entity1.setResistanceForce(Rs);

                for (int j = 6; j < 11; j++) {
                    switch (j) {
                        case 6:
                            Ds = BigDecimal.valueOf(2.032).subtract(BigDecimal.valueOf(0.007).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD6(Ds);
                            break;
                        case 7:
                            Ds = BigDecimal.valueOf(1.977).subtract(BigDecimal.valueOf(0.006).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD7(Ds);
                            break;
                        case 8:
                            Ds = BigDecimal.valueOf(1.975).subtract(BigDecimal.valueOf(0.005).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD8(Ds);
                            break;
                        case 9:
                            Ds = BigDecimal.valueOf(1.866).subtract(BigDecimal.valueOf(0.004).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD9(Ds);
                            break;
                        case 10:
                            Ds = BigDecimal.valueOf(1.74).subtract(BigDecimal.valueOf(0.003).multiply(Rs)).setScale(3, RoundingMode.HALF_UP);
                            if (Ds.compareTo(BigDecimal.valueOf(0)) < 1) {
                                Ds = BigDecimal.valueOf(0.05);
                            }
                            entity1.setD10(Ds);
                            break;
                    }
//                        //Ci
//                        BigDecimal ci;
//                        //如果ci这个字段是空的，那就取默认值
//                        if (PlatformObjectUtils.isEmpty(cbcpInfoEntity.getCorrectionCoefficient())) {
//                            ci = BigDecimal.valueOf(-0.35);
//                        } else {
//                            //用ci的id查出来ci的值
//                            String ciIds = cbcpInfoEntity.getCorrectionCoefficient();//修正系数Ci
//                            List<ZqtEntity> zqtList = zqtCiRepository.getZqtById(ciIds);
//                            ci = BigDecimal.valueOf(zqtList.stream().mapToDouble(ZqtEntity::getCiValue).sum());
//                        }
                    Dsm = Ds.multiply(BigDecimal.valueOf(1).add(ci)).setScale(2,
                            RoundingMode.HALF_UP);
                    // Dsm = BigDecimal.valueOf(Math.random());


                    switch (j) {
                        case 6:
                            entity1.setDegree6(Dsm);
                            break;
                        case 7:
                            entity1.setDegree7(Dsm);
                            break;
                        case 8:
                            entity1.setDegree8(Dsm);
                            break;
                        case 9:
                            entity1.setDegree9(Dsm);
                            break;
                        case 10:
                            entity1.setDegree10(Dsm);
                            break;
                    }
                    JSONObject jsonObject1 = null;
                    if (jsonMap1.containsKey(j)) {
                        jsonObject1 = jsonMap1.get(j);
                    } else {
                        jsonObject1 = new JSONObject();
                    }
                    jsonObject1.put("f" + i, Dsm);
                    jsonMap1.put(j, jsonObject1);
                    String DsmL = null;
                    if (Dsm.compareTo(BigDecimal.valueOf(0.1)) < 1) {
                        DsmL = "基本完好";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.1)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.3)) < 1) {
                        DsmL = "轻微破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.3)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.55)) < 1) {
                        DsmL = "中等破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.55)) > 0 && Dsm.compareTo(BigDecimal.valueOf(0.85)) < 1) {
                        DsmL = "严重破坏";
                    } else if (Dsm.compareTo(BigDecimal.valueOf(0.85)) > 0) {
                        DsmL = "毁坏";
                    }
                    JSONObject jsonObject2 = null;
                    if (jsonMap2.containsKey(j)) {
                        jsonObject2 = jsonMap2.get(j);
                    } else {
                        jsonObject2 = new JSONObject();
                    }
                    jsonObject2.put("floor" + i, DsmL);
                    jsonMap2.put(j, jsonObject2);

                    Map<String, Integer> map = null;
                    if (mapMap.containsKey(j)) {
                        map = mapMap.get(j);
                    } else {
                        map = new HashMap<>();
                    }
                    Integer integer = 0;
                    if (map.containsKey(DsmL)) {
                        integer = map.get(DsmL);
                        integer++;
                    } else {
                        integer = 1;
                    }
                    map.put(DsmL, integer);
                    mapMap.put(j, map);
                }
                //后台计算入库
                if (PlatformObjectUtils.isNotEmpty(cbcpInfoParam.getIds())) {
                    saveBrickConcreteDestroyCalc(entity1);
                }
                cztBrickConcreteDestroyCalcs.add(entity1);
                for (int k = 6; k < 11; k++) {
                    CztBrickConcreteDestroyResult entity = new CztBrickConcreteDestroyResult();
                    entity.setProjectId(cbcpInfoEntity.getCbcpiId());
                    entity.setBreakState(k + "度");
                    entity.setJsonData1(jsonMap1.get(k).toJSONString());
                    entity.setJsonData2(jsonMap2.get(k).toJSONString());
                    Integer num = 0;
                    String conclusion = "";
                    for (Map.Entry<String, Integer> entry : mapMap.get(k).entrySet()) {
                        if (num.compareTo(entry.getValue()) == 0) {
                            conclusion = conclusion + "," + entry.getKey();
                        } else if (num.compareTo(entry.getValue()) < 0) {
                            conclusion = entry.getKey();
                            num = entry.getValue();
                        }
                    }
                    if (conclusion.indexOf(",") == 0) {
                        conclusion = conclusion.substring(1);
                    }
                    entity.setConclusion(conclusion);
                    if (PlatformObjectUtils.isNotEmpty(cbcpInfoParam.getIds())) {
                        saveCztBrickConcreteDestroyResult(entity);
                    }
                    cztBrickConcreteDestroyResults.add(entity);
                }
            }
            PobStructureVO data = getData1(cztBrickConcreteDestroyCalcs, cztBrickConcreteDestroyResults);
            data.setCiIds(ciId);
            return RestResponse.succeed(data);
        } catch (Exception e) {
            String errorMessage = "计算失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse updatePobStructure(List<Map<String, Object>> cbcpInfoParam) {
        for (Map<String, Object> map : cbcpInfoParam) {
            CbcpInfoEntity cbcpInfoEntity = JSON.parseObject(JSON.toJSONString(map), CbcpInfoEntity.class);
            CbcpInfoEntity cbcById = bacInformationRepository.getCbcById1(cbcpInfoEntity.getCbcpiId());
            UpdateUtil.copyNullProperties(cbcById, cbcpInfoEntity);
            cbcpInfoEntity.setUpdateUser(PlatformSessionContext.getUserID());
            cbcpInfoEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
            bacInformationRepository.updateCbc(cbcpInfoEntity);
        }
        return RestResponse.succeed("修改成功！");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse updatePobStructure1(List<Map<String, Object>> cbcbInfoParam) {
        String userID = PlatformSessionContext.getUserID();
        // userID="80cd530287e54c6788925adf2dfc9da1";
        for (Map<String, Object> map : cbcbInfoParam) {
            CbcbInfoEntity cbcbInfoEntity = JSON.parseObject(JSON.toJSONString(map), CbcbInfoEntity.class);
            CbcbInfoEntity cbcById = bacInformationRepository.getCbcbiById(cbcbInfoEntity.getCbcbiId());
            UpdateUtil.copyNullProperties(cbcById, cbcbInfoEntity);
            cbcbInfoEntity.setUpdateUser(userID);
            cbcbInfoEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
            bacInformationRepository.updateCbcbInfo(cbcbInfoEntity);
        }
        return RestResponse.succeed("修改成功！");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse updatePobStructure2(List<Map<String, Object>> cbcbDetailParam) {
        String userID = PlatformSessionContext.getUserID();
        // userID="80cd530287e54c6788925adf2dfc9da1";
        for (Map<String, Object> map : cbcbDetailParam) {
            CbcbDetailEntity cbcbDetailEntity = JSON.parseObject(JSON.toJSONString(map), CbcbDetailEntity.class);
            CbcbDetailEntity cbcById = bacInformationRepository.getCbcbDetailById(cbcbDetailEntity.getCbcbdId());
            UpdateUtil.copyNullProperties(cbcById, cbcbDetailEntity);
            cbcbDetailEntity.setUpdateUser(userID);
            cbcbDetailEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
            bacInformationRepository.updateCbcbDetail(cbcbDetailEntity);
        }
        return RestResponse.succeed("修改成功！");
    }

    public void saveCztBrickConcreteDestroyResult(CztBrickConcreteDestroyResult entity) {
        entity.setCbcdrId(UUIDGenerator.getUUID());
        entity.setDelFlag("0");
        entity.setBreakStateSort(Integer.valueOf(entity.getBreakState().replace("度", "")));
        entity.setCreateUser(PlatformSessionContext.getUserID());
        entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        pobStructureRepository.saveBrickConcreteDestroyResults(entity);
    }

    public void saveBrickConcreteDestroyCalc(CztBrickConcreteDestroyCalc entity) {
        entity.setCbcdcId(UUIDGenerator.getUUID());
        entity.setDelFlag("0");
        entity.setCreateUser(PlatformSessionContext.getUserID());
        entity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
        pobStructureRepository.saveBrickConcreteDestroyCalc(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse saveOrUpdatePobStructure(Map<String, Object> map) {
        String userID = PlatformSessionContext.getUserID();
        // userID="80cd530287e54c6788925adf2dfc9da1";
        String user = sUserService.getSUser(userID);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        try {
            CbcbInfoEntity cbcbInfoEntity = JSON.parseObject(JSON.toJSONString(map.get("cbcbInfoEntity")), CbcbInfoEntity.class);
            List<CbcbDetailEntity> detailList = JSON.parseArray(JSON.toJSONString(map.get("detailList")), CbcbDetailEntity.class);
            List<CztBrickConcreteDestroyCalc> brickConcreteDestroyCalcList = JSON.parseArray(JSON.toJSONString(map.get("brickConcreteDestroyCalcList")), CztBrickConcreteDestroyCalc.class);
            List<CztBrickConcreteDestroyResult> brickConcreteDestroyResults = JSON.parseArray(JSON.toJSONString(map.get("brickConcreteDestroyResults")), CztBrickConcreteDestroyResult.class);

            //如果这个集合为空,计算状态为未计算
            if (PlatformObjectUtils.isEmpty(brickConcreteDestroyCalcList)) {
                cbcbInfoEntity.setCalculateOrNot("0");
            } else {
                cbcbInfoEntity.setCalculateOrNot("1");
            }

            if (PlatformObjectUtils.isNotEmpty(cbcbInfoEntity.getCbcbiId())) {
                //修改
                cbcbInfoEntity.setUpdateUser(userID);
                cbcbInfoEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.updateCbcbInfo(cbcbInfoEntity);
            } else {
                cbcbInfoEntity.setNumber(generationNumberUtil.getCityInitials(cbcbInfoEntity.getProvince()) +"-"+
                        generationNumberUtil.type(cbcbInfoEntity.getStructureType(), cbcbInfoEntity.getStructureType1()) +"-"+
                        generationNumberUtil.getFs(cbcbInfoEntity.getFortification()) +"-"+
                        generationNumberUtil.getGenerationNumber(RedisKeyConstants.CZT_ZHJG_KEY));
                cbcbInfoEntity.setDataType(FxfzConstants.CZT_ZHJG_INFO);
                cbcbInfoEntity.setCbcbiId(UUIDGenerator.getUUID());
                cbcbInfoEntity.setDelFlag("0");
                cbcbInfoEntity.setBasicLibrary("0");
                cbcbInfoEntity.setCreateUser(userID);
                cbcbInfoEntity.setUserName(sUser.getUserName());
                cbcbInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.savePobStructure1(cbcbInfoEntity);
            }
            detailList.forEach(it -> {
                if (PlatformObjectUtils.isNotEmpty(it.getCbcbdId())) {
                    //修改
                    it.setUpdateUser(userID);
                    it.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                    bacInformationRepository.updateCbcbDetail(it);
                } else {
                    it.setCbcbdId(UUIDGenerator.getUUID());
                    it.setCbcbiId(cbcbInfoEntity.getCbcbiId());
                    it.setDelFlag("0");
                    it.setCreateUser(userID);
                    it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                    bacInformationRepository.savePobStructure2(it);
                }
            });

            //计算出来的数据，不存在修改
            brickConcreteDestroyCalcList.forEach(it -> {
                it.setProjectId(cbcbInfoEntity.getCbcbiId());
                it.setDelFlag("0");
                it.setCbcdcId(UUIDGenerator.getUUID());
                it.setCreateUser(userID);
                it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                pobStructureRepository.saveBrickConcreteDestroyCalc(it);
            });
            brickConcreteDestroyResults.forEach(it -> {
                it.setProjectId(cbcbInfoEntity.getCbcbiId());
                it.setDelFlag("0");
                it.setCbcdrId(UUIDGenerator.getUUID());
                it.setBreakStateSort(Integer.valueOf(it.getBreakState().replace("度", "")));
                it.setCreateUser(userID);
                it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                pobStructureRepository.saveBrickConcreteDestroyResults(it);
            });
            return RestResponse.succeed("成功!");
        } catch (Exception e) {
            String errorMessage = "失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public RestResponse saveOrUpdatePobStructure1(CbcpInfoParam cbcpInfoParam) {
        try {
            CbcpInfoEntity cbcpInfoEntity = cbcpInfoParam.getCbcpInfoEntity();
            List<CztBrickConcreteDestroyCalc> brickConcreteDestroyCalcList = cbcpInfoParam.getBrickConcreteDestroyCalcList();
            List<CztBrickConcreteDestroyResult> brickConcreteDestroyResults = cbcpInfoParam.getBrickConcreteDestroyResults();
            //如果这个集合为空,计算状态为未计算
            if (PlatformObjectUtils.isEmpty(brickConcreteDestroyCalcList)) {
                cbcpInfoEntity.setCalculateOrNot("0");
            } else {
                cbcpInfoEntity.setCalculateOrNot("1");
            }

            if (PlatformObjectUtils.isNotEmpty(cbcpInfoEntity.getCbcpiId())) {
                //修改
                cbcpInfoEntity.setUpdateUser(PlatformSessionContext.getUserID());
                cbcpInfoEntity.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.updateCbc(cbcpInfoEntity);
            } else {
                cbcpInfoEntity.setNumber(generationNumberUtil.getCityInitials(cbcpInfoEntity.getProvince()) +
                        generationNumberUtil.type(cbcpInfoEntity.getStructureType(), cbcpInfoEntity.getStructureType1()) +
                        generationNumberUtil.getFs(cbcpInfoEntity.getFortification()) +
                        generationNumberUtil.getGenerationNumber(RedisKeyConstants.CZT_ZHJG_KEY));
                cbcpInfoEntity.setDataType(FxfzConstants.CZT_ZHJG_INFO);
                cbcpInfoEntity.setCbcpiId(UUIDGenerator.getUUID());
                cbcpInfoEntity.setDelFlag("0");
                cbcpInfoEntity.setCreateUser(PlatformSessionContext.getUserID());
                cbcpInfoEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                bacInformationRepository.savePobStructure(cbcpInfoEntity);
            }

            //计算出来的数据，不存在修改
            brickConcreteDestroyCalcList.forEach(it -> {
                it.setProjectId(cbcpInfoEntity.getCbcpiId());
                it.setDelFlag("0");
                it.setCbcdcId(UUIDGenerator.getUUID());
                it.setCreateUser(PlatformSessionContext.getUserID());
                it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                pobStructureRepository.saveBrickConcreteDestroyCalc(it);
            });
            brickConcreteDestroyResults.forEach(it -> {
                it.setProjectId(cbcpInfoEntity.getCbcpiId());
                it.setDelFlag("0");
                it.setCbcdrId(UUIDGenerator.getUUID());
                it.setBreakStateSort(Integer.valueOf(it.getBreakState().replace("度", "")));
                it.setCreateUser(PlatformSessionContext.getUserID());
                it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                pobStructureRepository.saveBrickConcreteDestroyResults(it);
            });
            return RestResponse.succeed("成功!");
        } catch (Exception e) {
            String errorMessage = "失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public RestResponse getById(String id) {
        JSONObject jsonObject = new JSONObject();
        try {
            //主表数据（建筑数据）
            CbcbInfoEntity entity = bacInformationRepository.getCbcbiById(id);
            //附件
            if (PlatformObjectUtils.isNotEmpty(entity.getAnnex())) {
                String[] ids = entity.getAnnex().split(",");
                ArrayList<String> list = new ArrayList<>();
                for (String annexId : ids) {
                    String attachName = attachmentInfoRepository.getAttach(annexId).getAttachName();
                    list.add(attachName);
                }
                entity.setAnnexNameList(list);
            }
            jsonObject.put("entity", entity);
            //子表数据（建筑的楼层数据）
            List<CbcbDetailEntity> detailList = bacInformationRepository.getCbcbdById(entity.getCbcbiId());
            jsonObject.put("detailList", detailList);
            //计算的结果数据
            List<CztBrickConcreteDestroyCalc> byProjectId1 = pobStructureRepository.getByProjectId1(id);
            List<CztBrickConcreteDestroyResult> byProjectId2 = pobStructureRepository.getByProjectId2(id);
            //初始化结果数据
            getData(jsonObject, byProjectId1, byProjectId2);
            return RestResponse.succeed(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail("查询失败！");
        }
    }

    @Override
    public RestResponse getById1(String id) {
//        PobStructureVO vo= new PobStructureVO();
        try {
            List<CztBrickConcreteDestroyCalc> byProjectId1 = pobStructureRepository.getByProjectId1(id);
            List<CztBrickConcreteDestroyResult> byProjectId2 = pobStructureRepository.getByProjectId2(id);
            PobStructureVO data = getData1(byProjectId1, byProjectId2);
            //附件
            CbcpInfoEntity entity = bacInformationRepository.getCbcById1(id);
            if (PlatformObjectUtils.isNotEmpty(entity.getAnnex())) {
                String[] ids = entity.getAnnex().split(",");
                ArrayList<String> list = new ArrayList<>();
                for (String annexId : ids) {
                    String attachName = attachmentInfoRepository.getAttach(annexId).getAttachName();
                    list.add(attachName);
                }
                entity.setAnnexNameList(list);
            }
            data.setEntity(entity);
            return RestResponse.succeed(data);
//            List<JSONObject> data1 = new ArrayList<>();//各层的抗力
//            List<JSONObject> data2 = new ArrayList<>();//每层不同烈度未修正的震害指数
//            List<JSONObject> data3 = new ArrayList<>();//各层不同烈度下修正后的震害指数
//            for (CztBrickConcreteDestroyCalc entity : byProjectId1) {
//                JSONObject object1 = new JSONObject();
//                object1.put("cs", entity.getCs());
//                object1.put("qtkjcd", entity.getQtkjcd());
//                object1.put("dzjlzsxs", entity.getDzjlzsxs());
//                object1.put("resistanceForce", entity.getResistanceForce());
//                data1.add(object1);
//                JSONObject object2 = new JSONObject();
//                object2.put("cs", entity.getCs());
//                object2.put("d7", entity.getD7());
//                object2.put("d8", entity.getD8());
//                object2.put("d9", entity.getD9());
//                object2.put("d10", entity.getD10());
//                data2.add(object2);
//                JSONObject object3 = new JSONObject();
//                object3.put("cs", entity.getCs());
//                object3.put("degree7", entity.getDegree7());
//                object3.put("degree8", entity.getDegree8());
//                object3.put("degree9", entity.getDegree9());
//                object3.put("degree10", entity.getDegree10());
//                data3.add(object3);
//            }
//            vo.setData1(data1);
//            vo.setData2(data2);
//            vo.setData3(data3);
//
//            List<JSONObject> data4 = new ArrayList<>();//各烈度不同楼层下修正后的震害指数
//            List<JSONObject> data5 = new ArrayList<>();//各烈度不同楼层下修正后的震害等级
//
//            for (CztBrickConcreteDestroyResult entity : byProjectId2) {
//                JSONObject object1 = JSON.parseObject(entity.getJsonData1());
//                object1.put("breakState", entity.getBreakState());
//                data4.add(object1);
//                JSONObject object2 = JSON.parseObject(entity.getJsonData2());
//                object2.put("breakState", entity.getBreakState());
//                object2.put("conclusion", entity.getConclusion());
//                data5.add(object2);
//            }
//            vo.setData4(data4);
//            vo.setData5(data5);
        } catch (Exception e) {
            e.printStackTrace();
            return RestResponse.fail("查询失败！");
        }
    }

    public static void getData(JSONObject jsonObject, List<CztBrickConcreteDestroyCalc> cztBrickConcreteDestroyCalcList,
                               List<CztBrickConcreteDestroyResult> cztBrickConcreteDestroyResultList) {
        List<JSONObject> data1 = new ArrayList<>();//各层的抗力
        List<JSONObject> data2 = new ArrayList<>();//每层不同烈度未修正的震害指数
        List<JSONObject> data3 = new ArrayList<>();//各层不同烈度下修正后的震害指数
//        List<CztBrickConcreteDestroyCalc> byProjectId1 = pobStructureRepository.getByProjectId1(id);
        for (CztBrickConcreteDestroyCalc entity : cztBrickConcreteDestroyCalcList) {
            JSONObject object1 = new JSONObject();
            object1.put("cs", entity.getCs());
            object1.put("qtkjcd", entity.getQtkjcd());
            object1.put("dzjlzsxs", entity.getDzjlzsxs());
            object1.put("resistanceForce", entity.getResistanceForce());
            object1.put("id", entity.getCbcdcId());
            data1.add(object1);
            JSONObject object2 = new JSONObject();
            object2.put("cs", entity.getCs());
            object2.put("d6", entity.getD6());
            object2.put("d7", entity.getD7());
            object2.put("d8", entity.getD8());
            object2.put("d9", entity.getD9());
            object2.put("d10", entity.getD10());
            data2.add(object2);
            JSONObject object3 = new JSONObject();
            object3.put("cs", entity.getCs());
            object3.put("degree6", entity.getDegree6());
            object3.put("degree7", entity.getDegree7());
            object3.put("degree8", entity.getDegree8());
            object3.put("degree9", entity.getDegree9());
            object3.put("degree10", entity.getDegree10());
            data3.add(object3);
        }
        jsonObject.put("data1", data1);
        jsonObject.put("data2", data2);
        jsonObject.put("data3", data3);

        List<JSONObject> data4 = new ArrayList<>();//各烈度不同楼层下修正后的震害指数
        List<JSONObject> data5 = new ArrayList<>();//各烈度不同楼层下修正后的震害等级
//        List<CztBrickConcreteDestroyResult> byProjectId2 = pobStructureRepository.getByProjectId2(id);
        for (CztBrickConcreteDestroyResult entity : cztBrickConcreteDestroyResultList) {
            JSONObject object1 = JSON.parseObject(entity.getJsonData1());
            object1.put("breakState", entity.getBreakState());
            data4.add(object1);
            JSONObject object2 = JSON.parseObject(entity.getJsonData2());
            object2.put("breakState", entity.getBreakState());
            object2.put("conclusion", entity.getConclusion());
            data5.add(object2);
        }
        jsonObject.put("data4", data4);
        jsonObject.put("data5", data5);
    }

    public static PobStructureVO getData1(List<CztBrickConcreteDestroyCalc> cztBrickConcreteDestroyCalcList,
                                          List<CztBrickConcreteDestroyResult> cztBrickConcreteDestroyResultList) {
        PobStructureVO vo = new PobStructureVO();
        List<JSONObject> data1 = new ArrayList<>();//各层的抗力
        List<JSONObject> data2 = new ArrayList<>();//每层不同烈度未修正的震害指数
        List<JSONObject> data3 = new ArrayList<>();//各层不同烈度下修正后的震害指数
//        List<CztBrickConcreteDestroyCalc> byProjectId1 = pobStructureRepository.getByProjectId1(id);
        for (CztBrickConcreteDestroyCalc entity : cztBrickConcreteDestroyCalcList) {
            JSONObject object1 = new JSONObject();
            object1.put("cs", entity.getCs());
            object1.put("qtkjcd", entity.getQtkjcd());
            object1.put("dzjlzsxs", entity.getDzjlzsxs());
            object1.put("resistanceForce", entity.getResistanceForce());
            object1.put("id", entity.getCbcdcId());
            data1.add(object1);
            JSONObject object2 = new JSONObject();
            object2.put("cs", entity.getCs());
            object2.put("d6", entity.getD6());
            object2.put("d7", entity.getD7());
            object2.put("d8", entity.getD8());
            object2.put("d9", entity.getD9());
            object2.put("d10", entity.getD10());
            data2.add(object2);
            JSONObject object3 = new JSONObject();
            object3.put("cs", entity.getCs());
            object3.put("degree6", entity.getDegree6());
            object3.put("degree7", entity.getDegree7());
            object3.put("degree8", entity.getDegree8());
            object3.put("degree9", entity.getDegree9());
            object3.put("degree10", entity.getDegree10());
            data3.add(object3);
        }
        vo.setData1(data1);
        vo.setData2(data2);
        vo.setData3(data3);

        List<JSONObject> data4 = new ArrayList<>();//各烈度不同楼层下修正后的震害指数
        List<JSONObject> data5 = new ArrayList<>();//各烈度不同楼层下修正后的震害等级
//        List<CztBrickConcreteDestroyResult> byProjectId2 = pobStructureRepository.getByProjectId2(id);
        for (CztBrickConcreteDestroyResult entity : cztBrickConcreteDestroyResultList) {
            JSONObject object1 = JSON.parseObject(entity.getJsonData1());
            object1.put("breakState", entity.getBreakState());
            data4.add(object1);
            JSONObject object2 = JSON.parseObject(entity.getJsonData2());
            object2.put("breakState", entity.getBreakState());
            object2.put("conclusion", entity.getConclusion());
            data5.add(object2);
        }
        vo.setData4(data4);
        vo.setData5(data5);
        return vo;
    }

    @Override
    public RestResponse queryPobStructure(CbcbInfoEntity cbcbInfoEntity, HttpServletRequest request) {
        try {
            int page = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            String userID = PlatformSessionContext.getUserID();
            userID = "80cd530287e54c6788925adf2dfc9da1";
            String role = roleService.getRoleByUserId(userID);
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                if (roleCode.equals(FxfzConstants.CZT_PRI_GL_ROLE) || roleCode.equals(FxfzConstants.CZT_COUN_GL_ROLE)) {
                    cbcbInfoEntity.setRole("0");
                } else {
                    cbcbInfoEntity.setRole("1");
                }
            }
            return RestResponse.succeed(pobStructureRepository.queryPobStructure(cbcbInfoEntity, page, size));
        } catch (Exception e) {
            String errorMessage = "查看失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public RestResponse queryPobStructure1(CbcpInfoEntity cbcpInfoEntity, HttpServletRequest request) {
        try {
            int page = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            String userID = PlatformSessionContext.getUserID();
            String role = roleService.getRoleByUserId(userID);
            List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
            for (Map roleMap : roleMaps) {
                String roleCode = (String) roleMap.get("roleCode");
                if (roleCode.equals(FxfzConstants.CZT_PRI_GL_ROLE) || roleCode.equals(FxfzConstants.CZT_COUN_GL_ROLE)) {
                    cbcpInfoEntity.setRole("0");
                } else {
                    cbcpInfoEntity.setRole("1");
                }
            }
            return RestResponse.succeed(pobStructureRepository.queryPobStructure1(cbcpInfoEntity, page, size));
        } catch (Exception e) {
            String errorMessage = "查看失败!";
            log.error(errorMessage, e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public void exportPobStructure(String cbcIds, HttpServletResponse response) {
        ArrayList<CbcbInfoEntity> list = new ArrayList<>();
        for (String id : cbcIds.split(",")) {
            CbcbInfoEntity entity = bacInformationRepository.getCbcbiById(id);
            list.add(entity);
        }
        try {
            FileUtil.exportExcel(list, "砖混结构信息", "sheet1", CbcbInfoEntity.class, "砖混结构信息.xlsx", response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void exportPobStructure1(String cbcIds, HttpServletResponse response) {
        ArrayList<CbcpInfoEntity> list = new ArrayList<>();
        for (String id : cbcIds.split(",")) {
            CbcpInfoEntity entity = bacInformationRepository.getCbcById1(id);
            CbcpInfoEntity cbcpInfoEntity = new CbcpInfoEntity();
            BeanUtil.copyPropertiesIgnoreEmpty(entity, cbcpInfoEntity);
            cbcpInfoEntity.setRegion(cbcpInfoEntity.getProvince() + "-" + cbcpInfoEntity.getCity() + "-" + cbcpInfoEntity.getCounty());
            cbcpInfoEntity.setSt(cbcpInfoEntity.getStructureType() + "-" + cbcpInfoEntity.getStructureType1());
            cbcpInfoEntity.setUse(cbcpInfoEntity.getPurpose() + "-" + cbcpInfoEntity.getPurpose1());
            list.add(cbcpInfoEntity);
        }
        try {
            FileUtil.exportExcel(list, "砖混结构信息", "sheet1", CbcpInfoEntity.class, "砖混结构信息.xlsx", response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
